Skip to content

Make RAG preparation and retrieval non-blocking#557

Open
GdoongMathew wants to merge 3 commits into
AsyncFuncAI:mainfrom
GdoongMathew:refactor/non_blocking_rag
Open

Make RAG preparation and retrieval non-blocking#557
GdoongMathew wants to merge 3 commits into
AsyncFuncAI:mainfrom
GdoongMathew:refactor/non_blocking_rag

Conversation

@GdoongMathew

Copy link
Copy Markdown
Contributor

Summary

The async chat endpoints (/chat/completions/stream and /ws/chat) call RAG.prepare_retriever() and RAG.call synchronously, performing multiple blocking work - git clone, file io operations, embedding API calls, and query embedding - directly on the event loop thread, freezing the service and stalling all concurrent requests).

This PR offloads the blocking work to worker threads so that the event loop stays responsive.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces asynchronous wrappers (aprepare_retriever and acall) for blocking RAG operations, utilizing asyncio.to_thread to prevent stalling the event loop. It also updates simple_chat.py and websocket_wiki.py to leverage these async methods and offload blocking calls like RAG initialization and file retrieval to worker threads. The review feedback highlights a critical issue with instantiating asyncio.Semaphore at the module level, which can lead to runtime errors due to binding to an inactive or incorrect event loop, and suggests lazily initializing the semaphore within the async method instead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread api/rag.py Outdated
Comment thread api/rag.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant